package com.cnhis.cloudhealth.clinical.util;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

@SuppressWarnings("all")
public class guavaCacheTest {

	public static void main(String[] args) {
		
		
		tet();

		/**
		 * LoadingCache LoadingCache1 = CacheBuilder.newBuilder()
		.maximumSize(100000).expireAfterAccess(10, TimeUnit.MINUTES)

		.build(

		new CacheLoader() {

			@Override
			public Object load(Object arg0) throws Exception {
				 
				return null;
			}

		});
			
					
					LoadingCache1.put("k2","v2");
				try {
					System.out.println( LoadingCache1.get("k2"));
				} catch (ExecutionException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
	 
		 
				try {
					System.out.println( LoadingCache1.get("k",new Callable () {

						@Override
						public Object call()   {
							 
							return "v";
						}
					})  );
				} catch (ExecutionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			 

		 */
		
		
		
		
		 

	}

	private static void tet() {
		Cache Cache1 = CacheBuilder.newBuilder()
				.maximumSize(100000).expireAfterAccess(15, TimeUnit.SECONDS)
				.build( );
		Cache1.put("k", "value");
		System.out.println(Cache1.getIfPresent("k2"));  //if no ret null
		try {
			System.out.println(Cache1.get("k3", new Callable () {

				@Override
				public Object call() throws Exception {
					// TODO Auto-generated method stub
					return "v2";
				}
			}));
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
